import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: () => import("@/views/index/index.vue"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
  },
];

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach(async (_to, _from, next) => {
  const title = _to.meta.title || "vue";
  document.title = title;
  // let routerToken = _to.query.session_token;
  // if (routerToken) {
  //   store.commit("SET_TOKEN", routerToken);
  // }
  // let token = store.state.token || routerToken;
  // if (!token && _to.path !== "/login") {
  //   next("/login");
  // } else {
    next();
  // }
});

export default router;
